package cn.pangza.mybatisplus.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    // 插入数据拦截器
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createtime", Date.class, new Date());
        this.strictInsertFill(metaObject, "createby", String.class, "pangza");
        this.strictInsertFill(metaObject, "deleteable", Integer.class, 0);
    }

    // 修改数据拦截器
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updatetime", Date.class, new Date());
        this.strictUpdateFill(metaObject, "updateby", String.class, "pangza");
    }
}
